package cn.com.bonc.khjy.schedu;


import cn.com.bonc.khjy.controller.KafkaController;
import cn.com.bonc.khjy.service.CommonService;
import cn.com.bonc.khjy.utils.JacksonMapper;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.thread.ThreadUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.*;

@Component
@RestController
public class ScheduTask {

    private Logger logger = LoggerFactory.getLogger(ScheduTask.class);

   /* @Autowired
    private CommonService service;*/

    @Autowired
    private KafkaController controller;

    @Autowired
    private FileFTPMonitor fileMonitor;
    private volatile boolean ftpFileStop = false;
    /*@Autowired
    private RestTemplate restTemplate;*/

    @Value("${topic.list}")
    private String topicList;



    @Scheduled(cron = "0 0/2 * * * ?")
    @RequestMapping("/test")
    public void scanDataBase(){

        if(!ftpFileStop){
            ftpFileStop=true;
            List<String> topics = new ArrayList<>();
            topics.addAll(Arrays.asList(topicList.split(",")));
            logger.debug("FTP查询到的topic信息 -> {}",topics);
            logger.debug("启动FTP消息渠道");
            controller.getData(topics);
        }
    }
}
